<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
List<Category> categories = (ArrayList<Category>) request.getAttribute("categories");
String success = (String) request.getAttribute("success");
Category category = (Category) request.getAttribute("category");
boolean hasChildren = (Boolean) request.getAttribute("hasChildren");
String form = (String) request.getAttribute("form");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<link href="/admin/plugins/forms/select/select2.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="/admin/plugins/forms/select/select2.min.js"></script>
<script type="text/javascript" src="/admin/js/custom/category_form.js"></script>
<script type="text/javascript">
<!--
var status = "<%=category.getStatus()%>";
//-->
</script>

				<jsp:include page="/admin/elements/heading_panel.jsp" />

                <!-- Build page from here: -->
                <div class="row-fluid">
					<div class="span12">
						<jsp:include page="/admin/elements/message_box.jsp" />
					
                    	<div class="box">
                        	<div class="title">
                            	<h4> 
                                	<span>Category Form</span>
                            	</h4>
							</div>
	                        <div class="content">
	                        	<form class="form-horizontal" method="post">       
	                            	<div class="form-row row-fluid">
	                                	<div class="span12">
	                                    	<div class="row-fluid">
	                                        	<label class="form-label span3" for="normal">Id</label>
	                                            <input type="text" name="id" class="span9 <%=check.get("id") != null ? "error" : "" %>" value="<%=category.getId()%>" />
	                                            <% if (check.get("id") != null) { %>
	                                            <label class="error" for="required" generated="true"><%=check.get("id") %></label>
	                                            <% } %>
											</div>
										</div>
									</div>
	                                   
	                                <div class="form-row row-fluid">
	                                	<div class="span12">
	                                    	<div class="row-fluid">
	                                        	<label class="form-label span3" for="normal">Name</label>
	                                            <input type="text" name="name" class="span9 <%=check.get("name") != null ? "error" : "" %>" value="<%=category.getName()%>" />
	                                            <% if (check.get("name") != null) { %>
	                                            <label class="error" for="required" generated="true"><%=check.get("name") %></label>
	                                            <% } %>
											</div>
										</div>
									</div>
									
									<div class="form-row row-fluid">
	                                	<div class="span12">
	                                    	<div class="row-fluid">
	                                        	<label class="form-label span3" for="normal">Description</label>
	                                        	<div class="controls-textarea span9">
		                                            <textarea name="desc" class="span9 <%=check.get("desc") != null ? "error" : "" %>"><%=category.getDesc()%></textarea>
		                                            <% if (check.get("desc") != null) { %>
		                                            <label class="error" for="required" generated="true"><%=check.get("desc") %></label>
		                                            <% } %>
		                                        </div>
											</div>
										</div>
									</div>
									
									<div class="form-row row-fluid">
	                                	<div class="span12">
	                                    	<div class="row-fluid">
	                                        	<label class="form-label span3" for="normal">Parent</label>
                                        		<div class="span6 controls">
		                                            <select id="parentId" name="parentId" class="nostyle <%=check.get("parentId") != null ? "error" : "" %>" <%=hasChildren==true? "disabled=\"disabled\"" : "" %> placeholder="Select Parent Category" style="width:100%;">
					                            		<option></option>
														<%
														for (int i = 0; i < categories.size(); i++) {
														%>
														<option value="<%=categories.get(i).getId()%>" <%=category.getParentId().equals(categories.get(i).getId()) ? "selected=\"selected\"" : ""%>>
															|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
															<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
														</option>
														<%
														}
														%>
					                            	</select>
		                                            <% if (check.get("parentId") != null) { %>
		                                            <label class="error" for="required" generated="true"><%=check.get("parentId") %></label>
		                                            <% } %>
	                                            </div>
											</div>
										</div>
									</div>
									
									<div class="form-row row-fluid">
	                                	<div class="span12">
	                                    	<div class="row-fluid">
	                                        	<label class="form-label span3" for="normal">Status</label>
                                        		<div class="span6 controls">
		                                            <select name="status" class="nostyle <%=check.get("status") != null ? "error" : "" %>">
					                            		<option value="0" label="Inactive">Inactive </option>
														<option value="1" label="Pending">Pending</option>
														<option value="2" label="Active">Active</option>
					                            	</select>
		                                            <% if (check.get("status") != null) { %>
		                                            <label class="error" for="required" generated="true"><%=check.get("status") %></label>
		                                            <% } %>
	                                            </div>
											</div>
										</div>
									</div>
									
									<div class="form-actions">
	                                	<button type="submit" class="btn btn-info">Save</button>
	                                    <button type="reset" class="btn">Reset</button>
									</div>                                           
	                    		</form>
							</div>
						</div><!-- End .box -->

					</div><!-- End .span6 -->

				</div><!-- End .row-fluid -->
                
<jsp:include page="/admin/layouts/footer.jsp" />